﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using Transfer.Utils;

namespace HyMaterialStatistic
{
	public partial class DlgMaterialStatisticParent : System.Windows.Forms.Form
	{
		public bool bLink { get; set; }

		public List<Dictionary<int, SatatisticDataInfo>> lstDicElems { get; set; }

		public DlgSpecialtyStatisticTable m_mainSetDlg { get; set; }

		public DlgMaterialStatisticParent()
		{
			this.InitializeComponent();
			this.lstDicElems = new List<Dictionary<int, SatatisticDataInfo>>();
		}

		public void ListDataSort(ref List<string> lstString)
		{
			if (lstString.Count <= 0)
			{
				return;
			}
			List<string> list = new List<string>();
			List<double> lstValue = new List<double>();
			foreach (string text in lstString)
			{
				char[] charAryItem = text.ToCharArray();
				double headNumber = this.GetHeadNumber(charAryItem);
				int index = this.ListSort(lstValue, headNumber);
				list.Insert(index, text);
			}
			lstString.Clear();
			lstString = list;
		}

		private double GetHeadNumber(char[] charAryItem)
		{
			double result = -1.0;
			int i = 0;
			while (i < charAryItem.Length)
			{
				if (!char.IsNumber(charAryItem[i]))
				{
					char[] array = new char[i];
					Array.ConstrainedCopy(charAryItem, 0, array, 0, i);
					string text = new string(array);
					if (text == "")
					{
						result = double.MaxValue;
						break;
					}
					result = Convert.ToDouble(text);
					break;
				}
				else
				{
					i++;
				}
			}
			return result;
		}

		private int ListSort(List<double> lstValue, double dValue)
		{
			int num = lstValue.Count;
			for (int i = 0; i < lstValue.Count; i++)
			{
				if (Geometry.LessThan(dValue, lstValue[i]))
				{
					num = i;
					break;
				}
			}
			lstValue.Insert(num, dValue);
			return num;
		}
	}
}
